package cn.autoOffice.controller;
/*
 *功能说明：请假控制层
 *@author 皮永浪
 *@Date 2023/3/29 11:08
 */

import cn.autoOffice.bean.pojo.Leave;
import cn.autoOffice.bean.vo.Result;
import cn.autoOffice.service.LeaveService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;

    //添加请假信息
    @PostMapping("addLeave")
    @ResponseBody
    // @RequiresRoles("financeUser")
    public String addLeaveInfo(Leave leave){
        boolean i = leaveService.addLeaveInfo(leave);
        if (i){
            return "0003:请假成功";
        }else {
            return "0004:请假失败";
        }
    }

    //查看请假信息
    @PostMapping("findLeave/{empName}/{pageNo}/{pageSize}")
    // @RequiresRoles("financeUser")
    public Result<PageInfo<Leave>> findExclusiveLeaveInfo(@PathVariable(value = "empName",required = false) String empName,
                                                          @PathVariable Integer pageNo,
                                                          @PathVariable Integer pageSize){
        PageHelper.startPage(pageNo,pageSize);
        List<Leave> leaves = leaveService.findExclusiveLeave(empName);
        PageInfo pageInfo=new PageInfo(leaves);
        System.out.println("====" + pageInfo.getTotal());
        return Result.success(pageInfo);
    }

     //更改审批状态
    @PostMapping("updateState")
    @ResponseBody
    // @RequiresRoles("financeUser")
    public String updateLeaveState(Leave leave){
        boolean i = leaveService.updateLeaveState(leave);
        if (i){
            return "0009:请假审批通过";
        }else {
            return "0010:请假审批失败";
        }
    }
}
